package com.heima.crm.controller;

import com.heima.crm.common.result.Result;
import com.heima.crm.pojos.dtos.ContractPageDto;
import com.heima.crm.pojos.entity.TbContract;
import com.heima.crm.service.ContractService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * 合同接口
 */
@RestController
@RequestMapping("/contract")
@Slf4j
public class ContractController {
    @Autowired
    private ContractService contractService;


    /**
     * 合同分页查询
     *
     * @param contractPageDto
     * @return
     */
    @GetMapping("/page")
    public Result pageQurry(ContractPageDto contractPageDto) {
        log.info("请求参数为:" + contractPageDto.toString());
        return contractService.pageQurry(contractPageDto);

    }

    /**
     * 合同详情
     *
     * @param id
     * @return
     */
    @GetMapping("/display/{id}")
    public Result display(@PathVariable Integer id) {
        log.info("请求参数为:" + id);
        return contractService.display(id);
    }

    /**
     * 合同文件上传
     *
     * @param file
     * @return
     */
    @PostMapping("/upload")
    public Result upload(MultipartFile file) {
        log.info("请求参数为:" + file);
        return contractService.upload(file);
    }

    /**
     * 新增合同
     *
     * @return
     */
    @PostMapping("/insert")
    public Result insert(@RequestBody TbContract tbContract) {
        log.info("请求参数为:" + tbContract.getContractUrl());
        return contractService.insert(tbContract);

    }

    /**
     * 合同预览
     *
     * @param id
     * @return
     */
    @GetMapping("/preview/{id}")
    public Result preview(@PathVariable Long id) {
        log.info("请求参数为:" + id);
        return contractService.preview(id);

    }

}
